<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize' 
import Cookies from 'js-cookie'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null, 
      a:0,
      b:0,
      c:0,
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.getCount();
      
    });
  },

  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    getCount(){
      this.initChart();  
    },
   
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          text: '统计',
          x: 'center',
          padding: [2,0,40,0],
          textStyle:{
                    color:'#0DB9F2',        //颜色
                    fontStyle:'normal',     //风格
                    fontWeight:'normal',    //粗细
                    fontFamily:'Microsoft yahei',   //字体
                    fontSize:16,     //大小
                    align:'center'   //水平对齐
                },
          //textAlign:'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
          
        },
        grid: {
          top: 40,
          left: '2%',
          right: '2%',
          bottom: '3%',
          containLabel: true
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['a1', 'a2', 'a3']
        },
        series: [
          {
            name: '统计',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['50%', '43%'],
            data: [
              { value: this.b, name: 'a1' },
              { value: this.a, name: 'a2' },
              { value: this.c, name: 'a3' }
            ],
            //data:undefined,
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    },
    
  }
}
</script>
